#include <iostream>
#include <vector>

// 基类模板
template <typename Derived>
class Base {
public:
    void interface() {
        // 基类提供公共接口，调用派生类的实现
        static_cast<Derived*>(this)->implementation();
    }

    void print() const {
        const Derived& derived = static_cast<const Derived&>(*this);
        for (const auto& elem : derived.data) {
            std::cout << elem << " ";
        }
        std::cout << std::endl;
    }
};

// 派生类
class Derived : public Base<Derived> {
public:
    std::vector<int> data;

    Derived(const std::initializer_list<int>& init) : data(init) {}

    void implementation() {
        std::cout << "Derived implementation" << std::endl;
    }
};

int main() {
    Derived d = {2, 0, 2, 4, 10};
    d.interface();  		// 输出: Derived implementation
    d.print();  			// 输出: 2 0 2 4 10
    return 0;
}